package Events.random;

import java.awt.Component;
import java.util.Random;

import javax.swing.JTextArea;

import structures.Player;
import structures.Spaceship;

public class EngineTrouble implements RandomEvent{

	@Override
	public void execute(Spaceship ship, JTextArea txt, Component parent) {
		Random rnd = new Random();
		int n = rnd.nextInt(100);
		switch(ship.getPace()){
		case STOPPED:
			break;
		case SLOW:
			if(n < 5){
				ship.breakEngine();
				txt.append("\nYou're having engine trouble, better fix it!\n");
				txt.append("Trying to fix engine...\n");
				String status = ((Player)(ship.getPlist().get(0))).getProfession().fixEngines(ship);
				txt.append(status + "\n");
			}
			break;
		case CAUTIOUSLY:
			if(n < 5){
				ship.breakEngine();
				txt.append("\nYou're having engine trouble, better fix it!\n");
				txt.append("Trying to fix engine...\n");
				String status = ((Player)(ship.getPlist().get(0))).getProfession().fixEngines(ship);
				txt.append(status + "\n");
			}
			break;
		case NORMALLY:
			if(n < 25){
				ship.breakEngine();
				txt.append("\nYou're having engine trouble, better fix it!\n");
				txt.append("Trying to fix engine...\n");
				String status = ((Player)(ship.getPlist().get(0))).getProfession().fixEngines(ship);
				txt.append(status + "\n");
			}
			break;
		case QUICKLY:
			if(n < 50){
				ship.breakEngine();
				txt.append("\nYou're having engine trouble, better fix it!");
				txt.append("Trying to fix engine...\n");
				String status = ((Player)(ship.getPlist().get(0))).getProfession().fixEngines(ship);
				txt.append(status + "\n");
			}
			break;
		}
	}

}
